package com.purang.web.exception;

import com.purang.web.common.BaseResponse;
import lombok.Getter;

/**
 * 业务异常
 *
 * @author Zheming Liu
 * @version 1.0-RELEASE
 * @since 1.0-RELEASE
 */
public class BusinessException extends RuntimeException implements BaseResponse {

    @Getter
    private Integer code;


    private BusinessException(Integer code, String message) {
        super(message);
        this.code = code;
    }

    private BusinessException(BaseResponse baseResponse) {
        super(baseResponse.getMessage());
        this.code = baseResponse.getCode();
    }

    public static BusinessException build(Integer code, String message) {
        return new BusinessException(code, message);
    }

    public static BusinessException build(BaseResponse baseResponse) {
        return new BusinessException(baseResponse);
    }
}
